//
//  DZDDetailCell.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2021/9/27.
//  Copyright © 2021 zwb. All rights reserved.
//

import UIKit
 
class ZyaDZDDetailCell: UITableViewCell {
   lazy var bg:UIView = {
      let v = UIView()
       v.backgroundColor = .white
       v.cornerRadius = 5
       return v
   }()
 
  override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
      super.init(style: style, reuseIdentifier: reuseIdentifier)
       self.contentView.addSubview(bg)
      self.contentView.backgroundColor = Theme.awModuleBgColor
       bg.snp.makeConstraints { make in
          make.top.equalTo(self.contentView).offset(3)
          make.left.equalTo(self.contentView).offset(6)
          make.right.equalTo(self.contentView).offset(-6)
          make.bottom.equalTo(self.contentView)
      }
      
   }
    var lastLab:UILabel?

  var arr:[JoinModel]? {
      didSet {
          if let arr = arr {
              for subv in bg.subviews {
                  subv.removeFromSuperview()
              }
              self.lastLab = nil
              for i in 0..<arr.count {
                  let lab = UILabel()
                  lab.text = arr[i].name
                  lab.font = UIFont.systemFont(ofSize: 15)

                  let right = UILabel()
                  right.text = arr[i].value
                  right.font = UIFont.systemFont(ofSize: 15)
                   if i == arr.count - 1 {
                      right.font = UIFont.boldSystemFont(ofSize: 17)
                      right.textColor = .red
                  }
                  bg.addSubview(lab)
                  bg.addSubview(right)
                  lab.snp.makeConstraints { make in
                      make.left.equalTo(bg).offset(10)
                      if lastLab.isSome {
                          make.top.equalTo(self.lastLab!.snp.bottom).offset(5)
                      } else {
                          make.top.equalTo(bg).offset(10)
                      }
                      if i == arr.count - 1 {
                          make.bottom.equalTo(bg).offset(-10)
                      }
                   }
                  right.snp.makeConstraints { make in
                      make.left.equalTo(bg).offset(100)
                           make.centerY.equalTo(lab)
                   }
                  self.lastLab = lab
              }
          }
      }
  }
  
  required init?(coder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
  
  override func setSelected(_ selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)

      // Configure the view for the selected state
  }

}
